﻿namespace _2_NovaAdmin.Application;

[AppStartup(200)]
public class Startup : AppStartup
{
    public override void ConfigureServices(IServiceCollection services)
    {
        if (services == null) throw new ArgumentNullException(nameof(services));
        // 注入MediatR,并扫描所有相关程序集
        services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(Startup).Assembly));
        services.AddTransient(typeof(IPipelineBehavior<,>), typeof(AppContextTransactionBehavior<,>));

        // 注入AutoMapper,在当前程序集自动找出所有继承自 Profile 的子类添加到配置中
        MapperConfiguration config = AutoMapperConfig.RegisterMappings();
        // 添加服务 启动配置 注入IMapper 接口
        services.AddSingleton<IMapper>(new Mapper(config));
    }

    public override void Configure(IApplicationBuilder app)
    {

    }
}